package myky.com.doctorapp.presenter;

import java.util.List;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.RxSubscribe;
import myky.com.doctorapp.contract.ConsultDetailsContract;
import myky.com.doctorapp.entity.ConsultDetailsEntity;
import myky.com.doctorapp.model.ConsultDetailsModel;


/**
 * Description:
 *
 * @author xiangyao
 * Created by 2019/3/11 11:41 AM
 */
public class ConsultDetailsPresenter extends BasePresenterIm<ConsultDetailsContract.View> implements ConsultDetailsContract.Presenter {
    ConsultDetailsModel consultDetailsModel;

    public ConsultDetailsPresenter() {
        consultDetailsModel = new ConsultDetailsModel();

    }

    @Override
    public void findConsultDeatails(int consultId) {

        consultDetailsModel.findConsultDeatails(consultId)
                .subscribe(new RxSubscribe<ConsultDetailsEntity>() {
                    /**
                     * @param specialistConsultEntity   咨询实体
                     */
                    @Override
                    protected void onSuccess(ConsultDetailsEntity specialistConsultEntity) {


                        if (specialistConsultEntity != null) {

                            mView.showDataSuccess(specialistConsultEntity);


                            List<ConsultDetailsEntity.SpecialistConsultBean.AnswerListBean> answerList = specialistConsultEntity.getSpecialistConsult().getAnswerList();

                            if (answerList != null && answerList.size() > 0) {

                                ConsultDetailsEntity.SpecialistConsultBean.AnswerListBean answerListBean = answerList.get(0);

                                mView.showDoctorRepeatContent(answerListBean);


                                //医生目前与患者的会话是单次的
                                ConsultDetailsEntity.SpecialistConsultBean.AnswerListBean.DoctorBean doctor = answerListBean.getDoctor();


                                mView.showRepeatDoctorInfo(doctor);

                            }


                            ConsultDetailsEntity.SpecialistConsultBean.ConsultDiseaseBean consultDisease = specialistConsultEntity.getSpecialistConsult().getConsultDisease();

                            mView.showConsultDisease(consultDisease);


                            ConsultDetailsEntity.SpecialistConsultBean.DoctorBean doctor1 = specialistConsultEntity.getSpecialistConsult().getDoctor();

                            mView.showDoctorInfo(doctor1);


                        }


                    }

                    @Override
                    protected void onFailed(int code, String msg) {
                        mView.logCat(msg);

                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        addSubscription(d);
                    }
                });

    }
}
